package com.ruoyi.school.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.enums.FileTypeEnum;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileTypeUtils;
import com.ruoyi.school.domain.*;
import com.ruoyi.school.domain.vo.*;
import com.ruoyi.school.enums.AuditStatusEnum;
import com.ruoyi.school.enums.AuditTypeEnum;
import com.ruoyi.school.enums.WallStateEnum;
import com.ruoyi.school.handler.wall.WallTopThree;
import com.ruoyi.school.service.*;
import com.ruoyi.school.mapper.PacAcademicOutputMapper;
import com.ruoyi.school.utils.CommonUtils;
import com.ruoyi.system.domain.TableData;
import com.ruoyi.system.service.ReslutLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

import static com.ruoyi.common.utils.PageUtils.startPage;
import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;

/**
 * @author jeremylin
 * @description 针对表【academic_output(学术成果表)】的数据库操作Service实现
 * @createDate 2025-05-24 17:35:38
 */
@Service
public class AcademicOutputServiceImpl extends ServiceImpl<PacAcademicOutputMapper, PacAcademicOutput>
        implements AcademicOutputService {

    @Resource
    private StudentService studentService;

    @Resource
    private PacAuditRecordsService pacAuditRecordsService;

    @Resource
    private PacAcademicOutputMapper pacAcademicOutputMapper;

    @Resource
    private PacTeacherService pacTeacherService;

    @Resource
    private ReslutLevelService reslutLevelService;

    @Resource
    private PacClassTeacherService pacClassTeacherService;

    @Autowired
    private PacAcademicOutputParticipationService pacAcademicOutputParticipationService;

    @Override
    public TableData<PacAcademicOutputVo> getList(PacAcademicOutputVo academicOutput) {
        // 查询学生信息
        Student studentParams = new Student();
        studentParams.setStuName(academicOutput.getStuName());
        studentParams.setStuNum(academicOutput.getStuNum());
        studentParams.setStuFaculties(academicOutput.getStuFaculties());
        studentParams.setStuPhone(academicOutput.getStuPhone());
        studentParams.setYearEnrollment(academicOutput.getYearEnrollment());
        studentParams.setStuClass(academicOutput.getStuClass());

        if (academicOutput.getTeacherType() != null) {
            List<PacClassInfoVo> pacClassInfoVos;
            if (academicOutput.getTeacherType() == 0) {
                // 获取当前老师绑定的班级id
                pacClassInfoVos = pacClassTeacherService.selectByTeacherByKey(getLoginUser().getUser(), "teacher");
            } else if (academicOutput.getTeacherType() == 1) {
                pacClassInfoVos = pacClassTeacherService.selectByTeacherByKey(getLoginUser().getUser(), "teacher2");
            } else {
                pacClassInfoVos = pacClassTeacherService.selectByTeacherByKey(getLoginUser().getUser(), "duizhang");
            }
            if (pacClassInfoVos != null && !pacClassInfoVos.isEmpty()) {
                List<Integer> classIds = pacClassInfoVos.stream().map(PacClass::getId).collect(Collectors.toList());
                // 设置当前老师可以查询的班级
                studentParams.setClassIds(classIds);
            }

            if (pacClassInfoVos.isEmpty()) {
                return TableData.<PacAcademicOutputVo>builder()
                        .total(0L)
                        .build();

            }
        }


        List<Student> studentSearch = studentService.selectInfo(studentParams);
        if (!studentSearch.isEmpty()) {
            List<Integer> ids = studentSearch.stream().map(Student::getId).collect(Collectors.toList());
            academicOutput.setStuIds(ids);
        }

        startPage();
//        LambdaQueryChainWrapper<PacAcademicOutput> queryChainWrapper = lambdaQuery()
//                .likeRight(StringUtils.isNotEmpty(academicOutput.getStuName()), PacAcademicOutput::getStuName, academicOutput.getStuName())
//                .eq(StringUtils.isNotEmpty(academicOutput.getStuNum()), PacAcademicOutput::getStuNum, academicOutput.getStuNum())
//                .eq(Objects.nonNull(academicOutput.getAcAudit()), PacAcademicOutput::getAcAudit, academicOutput.getAcAudit())
//                .eq(Objects.nonNull(academicOutput.getAcWall()), PacAcademicOutput::getAcWall, academicOutput.getAcWall())
//                .eq(Objects.nonNull(academicOutput.getStuId()), PacAcademicOutput::getStuId, academicOutput.getStuId())
//                .likeRight(Objects.nonNull(academicOutput.getAwardLevel()), PacAcademicOutput::getAwardLevel, academicOutput.getAwardLevel())
//                .eq(Objects.nonNull(academicOutput.getResultTypeId()), PacAcademicOutput::getResultTypeId, academicOutput.getResultTypeId())
//                .in(Objects.nonNull(academicOutput.getStuIds()), PacAcademicOutput::getStuId, academicOutput.getStuIds());

//        List<PacAcademicOutput> list = queryChainWrapper.list();
        List<PacAcademicOutput> list = pacAcademicOutputMapper.getList(academicOutput);
        // 找到学生id
        List<Long> stuIds = list.stream().map(PacAcademicOutput::getStuId).collect(Collectors.toList());
        List<Student> students = studentService.selectByStuIds(stuIds);
        Map<Integer, Student> studentMap = students.stream().collect(Collectors.toMap(Student::getId, student -> student));
        ArrayList<PacAcademicOutputVo> academicOutputVos = new ArrayList<>();


        // 获取所有类型ID
        List<Long> resultTypeIds = list.stream().map(PacAcademicOutput::getResultTypeId).collect(Collectors.toList());
        List<PacReslutLevel> resultTypes = reslutLevelService.selectByResultTypeIds(resultTypeIds);
        Map<Integer, PacReslutLevel> resultTypeMap = resultTypes.stream().collect(Collectors.toMap(PacReslutLevel::getId, pacReslutLevel -> pacReslutLevel));
        list.forEach(item -> {
            PacAcademicOutputVo vo = new PacAcademicOutputVo();
            vo.setId(item.getId());
            vo.setAcTitle(item.getAcTitle());
            vo.setAcFile(item.getAcFile());
            vo.setAcAudit(item.getAcAudit());
            vo.setAcWall(item.getAcWall());
            vo.setStuId(item.getStuId());
            vo.setStuName(item.getStuName());
            vo.setStuNum(item.getStuNum());
            Student student = studentMap.get(item.getStuId().intValue());
            vo.setStuClass(student.getStuClass());
            vo.setStuFaculties(student.getStuFaculties());
            vo.setYearEnrollment(student.getYearEnrollment());

            String instructorTeacherId = item.getInstructorTeacherId();
            List<PacTeacher> teachers = pacTeacherService.listByIds(Arrays.asList(instructorTeacherId.split(",")));
            vo.setTeachers(teachers);

            PacTeacher academicTeacherInfo = pacTeacherService.getAcademicTeacherInfo(student.getClassId());
            if (academicTeacherInfo != null) {
                vo.setAcademicTeacher(academicTeacherInfo.getTeacherName());
            }

            // 获奖等级
            vo.setAwardLevel(item.getAwardLevel());
            vo.setResultTypeId(item.getResultTypeId());

            // 获取赛事等级
            PacReslutLevel pacReslutLevel = resultTypeMap.get(item.getResultTypeId().intValue());
            if (pacReslutLevel != null) {
                vo.setRecognitionLevel(pacReslutLevel.getResLevel());
                vo.setRecognitionName(pacReslutLevel.getResName());
            }

            // 把团队成员查出来
            List<AcademicOutputParticipationListVo> participants = pacAcademicOutputParticipationService.getParticipants(item.getId());
            vo.setParticipants(participants);

            academicOutputVos.add(vo);
        });

        PageInfo pageInfo = new PageInfo(list);

        TableData<PacAcademicOutputVo> tableData = TableData.<PacAcademicOutputVo>builder()
                .data(academicOutputVos)
                .total(pageInfo.getTotal())
                .build();

        return tableData;
    }

    @Override
    public PacAcademicOutput getDetails(PacAcademicOutput pacAcademicOutput) {
        if (pacAcademicOutput.getId() == null) {
            throw new BaseException("id不能为空");
        }
        PacAcademicOutput one = lambdaQuery().eq(PacAcademicOutput::getId, pacAcademicOutput.getId()).one();
        String instructorTeacherId = one.getInstructorTeacherId();
        List<String> list = Arrays.asList(instructorTeacherId.split(","));
        List<Long> collect = list.stream().map(Long::valueOf).collect(Collectors.toList());
        one.setTeacherIds(collect);
        // 赛事名称
        PacReslutLevel byId = reslutLevelService.getById(one.getResultTypeId());
        one.setRecognitionName(byId.getResName());

        // 查询团队成员ids
        List<Long> memberIds = pacAcademicOutputParticipationService.selectMemberIds(pacAcademicOutput.getId());
        one.setMemberIds(memberIds);

        return one;
    }

    /**
     * 新增，学术成果记录
     * 1、添加审核记录
     *
     * @param pacAcademicOutput
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean add(PacAcademicOutput pacAcademicOutput) {
        if (pacAcademicOutput.getStuId() == null) {
            throw new BaseException("学生id不能为空");
        }

        if (pacAcademicOutput.getTeacherIds() == null) {
            throw new BaseException("请选择指导老师");
        }

        // 插入学生信息
        Long stuId = pacAcademicOutput.getStuId();
        Student student = studentService.getById(stuId);
        pacAcademicOutput.setStuName(student.getStuName());
        pacAcademicOutput.setStuNum(student.getStuNum());

        List<Long> teacherIds = pacAcademicOutput.getTeacherIds();
        // 逗号分隔
        String teacherIdsStr = StringUtils.join(teacherIds, ",");
        pacAcademicOutput.setInstructorTeacherId(teacherIdsStr);
        if (Objects.nonNull(pacAcademicOutput.getAcFile())) {
            FileTypeEnum fileTypeName = FileTypeUtils.getFileTypeName(pacAcademicOutput.getAcFile());
            pacAcademicOutput.setAcFileType(fileTypeName.getCode());
        }


        if (save(pacAcademicOutput)) {
            PacAuditRecords pacAuditRecords = getPacAuditRecords(pacAcademicOutput, student);

            if (pacAuditRecordsService.add(pacAuditRecords)) {
                return true;
            }
        }
        return false;
    }


    @Override
    public boolean edit(PacAcademicOutput pacAcademicOutput) {
        Long id = pacAcademicOutput.getId();

        PacAcademicOutput byId = getById(id);

        if (byId == null) {
            throw new BaseException("记录异常");
        }

        // 判断状态，如果已通过不让他更新
        if (byId.getAcAudit().equals(AuditStatusEnum.AUDITED.getCode())) {
            throw new BaseException("已通过，请勿修改");
        }

        Long stuId = pacAcademicOutput.getStuId();
        Student student = studentService.getById(stuId);
        pacAcademicOutput.setStuName(student.getStuName());
        pacAcademicOutput.setStuNum(student.getStuNum());

        if (Objects.nonNull(pacAcademicOutput.getAcFile())) {
            FileTypeEnum fileTypeName = FileTypeUtils.getFileTypeName(pacAcademicOutput.getAcFile());
            pacAcademicOutput.setAcFileType(fileTypeName.getCode());
        }

        List<Long> teacherIds = pacAcademicOutput.getTeacherIds();
        // 逗号分隔
        String teacherIdsStr = StringUtils.join(teacherIds, ",");
        pacAcademicOutput.setInstructorTeacherId(teacherIdsStr);

        // 重置记录状态
        pacAcademicOutput.setAcAudit(AuditStatusEnum.UNAUDITED.getCode());
        if (updateById(pacAcademicOutput)) {
            PacAuditRecords pacAuditRecords = getPacAuditRecords(pacAcademicOutput, student);
            pacAuditRecordsService.updateByRecord(pacAuditRecords);

            // 先删除团队成员
            pacAcademicOutputParticipationService.deleteByOutPutId(pacAcademicOutput.getId());
            // 重新添加
            if (pacAcademicOutput.getMemberIds() != null) {
                List<Student> students = studentService.selectByStuIds(pacAcademicOutput.getMemberIds());
                students.forEach(item -> {
                    PacAcademicOutputParticipation pacAcademicOutputParticipation = new PacAcademicOutputParticipation();
                    pacAcademicOutputParticipation.setOutputId(pacAcademicOutput.getId());
                    pacAcademicOutputParticipation.setParticipantId(item.getId().longValue());
                    pacAcademicOutputParticipationService.join(pacAcademicOutputParticipation);
                });
            }
            return true;
        }
        return false;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean delete(PacAcademicOutput pacAcademicOutput) {
        if (removeById(pacAcademicOutput)) {
            // 同时删除审批记录
            pacAuditRecordsService.deleteByOutPutId(pacAcademicOutput.getId(), AuditTypeEnum.PAC_WALL_TYPE_ACADEMIC.getCode());
            return true;
        }
        return false;
    }

    /**
     * 上墙
     *
     * @param academicCommonVo
     * @return
     */
    @Override
    public boolean wall(AcademicCommonVo academicCommonVo) {
        List<Long> ids = academicCommonVo.getIds();
        if (ids != null && !ids.isEmpty()) {
            List<PacAcademicOutput> list = new ArrayList<>();
            ids.forEach(item -> {
                PacAcademicOutput pacAcademicOutput = new PacAcademicOutput();
                pacAcademicOutput.setId(item);
                pacAcademicOutput.setAcWall(2);
                list.add(pacAcademicOutput);
            });
            if (updateBatchById(list)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 审批
     *
     * @param pacAcademicOutput
     */
    @Override
    public void audit(PacAcademicOutput pacAcademicOutput) {
        updateById(pacAcademicOutput);
    }

    /**
     * 获取学生的学术成果
     *
     * @param pacAcademicOutput
     * @return
     */
    @Override
    public ArrayList<PacAcademicOutputVo> myList(PacAcademicOutput pacAcademicOutput) {
        Student student = CommonUtils.getStudent();
        if (student != null) {

            List<PacAcademicOutput> list = lambdaQuery()
                    .likeRight(StringUtils.isNotEmpty(pacAcademicOutput.getAcTitle()),
                            PacAcademicOutput::getAcTitle, pacAcademicOutput.getAcTitle())
                    .eq(Objects.nonNull(pacAcademicOutput.getAcAudit()), PacAcademicOutput::getAcAudit, pacAcademicOutput.getAcAudit())
                    .eq(Objects.nonNull(pacAcademicOutput.getAcFileType()), PacAcademicOutput::getAcFileType, pacAcademicOutput.getAcFileType())
                    .eq(PacAcademicOutput::getStuId, student.getId())
                    .eq(Objects.nonNull(pacAcademicOutput.getResultTypeId()), PacAcademicOutput::getResultTypeId, pacAcademicOutput.getResultTypeId())
                    .between(Objects.nonNull(pacAcademicOutput.getStartTime()), PacAcademicOutput::getCreateTime, pacAcademicOutput.getStartTime(), pacAcademicOutput.getEndTime())
                    .apply(Objects.nonNull(pacAcademicOutput.getTeacherId()), "FIND_IN_SET({0}, instructor_teacher_id) > 0", pacAcademicOutput.getTeacherId())
                    .list();

            ArrayList<PacAcademicOutputVo> academicOutputVos = new ArrayList<>();

            // 获取所有类型ID
            List<Long> resultTypeIds = list.stream().map(PacAcademicOutput::getResultTypeId).collect(Collectors.toList());
            List<PacReslutLevel> resultTypes = reslutLevelService.selectByResultTypeIds(resultTypeIds);
            Map<Integer, PacReslutLevel> resultTypeMap = resultTypes.stream().collect(Collectors.toMap(PacReslutLevel::getId, pacReslutLevel -> pacReslutLevel));

            list.forEach(item -> {
                PacAcademicOutputVo vo = new PacAcademicOutputVo();
                vo.setId(item.getId());
                vo.setAcTitle(item.getAcTitle());
                vo.setAcFile(item.getAcFile());
                vo.setAcAudit(item.getAcAudit());
                vo.setAcWall(item.getAcWall());
                vo.setStuId(item.getStuId());
                vo.setStuName(item.getStuName());
                vo.setStuNum(item.getStuNum());
                vo.setStuClass(student.getStuClass());
                vo.setStuFaculties(student.getStuFaculties());
                vo.setYearEnrollment(student.getYearEnrollment());
                vo.setAcFileType(item.getAcFileType());
                vo.setResultTypeId(item.getResultTypeId());

                String instructorTeacherId = item.getInstructorTeacherId();
                List<PacTeacher> teachers = pacTeacherService.listByIds(Arrays.asList(instructorTeacherId.split(",")));
                vo.setTeachers(teachers);

                PacTeacher academicTeacherInfo = pacTeacherService.getAcademicTeacherInfo(student.getClassId());
                if (academicTeacherInfo != null) {
                    vo.setAcademicTeacher(academicTeacherInfo.getTeacherName());
                }

                // 获奖等级
                vo.setAwardLevel(item.getAwardLevel());

                // 获取赛事等级
                PacReslutLevel pacReslutLevel = resultTypeMap.get(item.getResultTypeId().intValue());
                if (pacReslutLevel != null) {
                    vo.setRecognitionLevel(pacReslutLevel.getResLevel());
                    vo.setRecognitionName(pacReslutLevel.getResName());
                }

                // 把团队成员查出来
                List<AcademicOutputParticipationListVo> participants = pacAcademicOutputParticipationService.getParticipants(item.getId());
                vo.setParticipants(participants);

                academicOutputVos.add(vo);
            });
            return academicOutputVos;
        }
        return new ArrayList<>();
    }

    /**
     * 学生新增学术成果
     *
     * @param pacAcademicOutput
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addByStu(PacAcademicOutput pacAcademicOutput) {
        if (pacAcademicOutput.getTeacherIds() == null) {
            throw new BaseException("请选择指导老师");
        }
        // 插入学生信息
        Student student = CommonUtils.getStudent();
        insertRecord(pacAcademicOutput, student);
        if (pacAcademicOutput.getMemberIds() != null) {
            List<Student> students = studentService.selectByStuIds(pacAcademicOutput.getMemberIds());
            students.forEach(item -> {
                PacAcademicOutputParticipation pacAcademicOutputParticipation = new PacAcademicOutputParticipation();
                pacAcademicOutputParticipation.setOutputId(pacAcademicOutput.getId());
                pacAcademicOutputParticipation.setParticipantId(item.getId().longValue());
                pacAcademicOutputParticipationService.join(pacAcademicOutputParticipation);
            });
        }
        return true;
    }

    private boolean insertRecord(PacAcademicOutput pacAcademicOutput, Student student) {
        pacAcademicOutput.setStuName(student.getStuName());
        pacAcademicOutput.setStuNum(student.getStuNum());
        pacAcademicOutput.setStuId(student.getId().longValue());

        if (Objects.nonNull(pacAcademicOutput.getAcFile())) {
            FileTypeEnum fileTypeName = FileTypeUtils.getFileTypeName(pacAcademicOutput.getAcFile());
            pacAcademicOutput.setAcFileType(fileTypeName.getCode());
        }

        List<Long> teacherIds = pacAcademicOutput.getTeacherIds();
        // 逗号分隔
        String teacherIdsStr = StringUtils.join(teacherIds, ",");
        pacAcademicOutput.setInstructorTeacherId(teacherIdsStr);

        if (save(pacAcademicOutput)) {
            PacAuditRecords pacAuditRecords = getPacAuditRecords(pacAcademicOutput, student);
            // 插入审核记录
            if (pacAuditRecordsService.add(pacAuditRecords)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 学术编辑学术成果
     *
     * @param pacAcademicOutput
     * @return
     */
    @Override
    public boolean editByStu(PacAcademicOutput pacAcademicOutput) {
        Student logInStu = CommonUtils.getStudent();
        Student student = studentService.getById(logInStu.getId());
        pacAcademicOutput.setStuName(student.getStuName());
        pacAcademicOutput.setStuNum(student.getStuNum());

        if (Objects.nonNull(pacAcademicOutput.getAcFile())) {
            FileTypeEnum fileTypeName = FileTypeUtils.getFileTypeName(pacAcademicOutput.getAcFile());
            pacAcademicOutput.setAcFileType(fileTypeName.getCode());
        }

        if (updateById(pacAcademicOutput)) {
            return true;
        }
        return false;
    }

    /**
     * 下墙
     *
     * @param academicCommonVo
     * @return
     */
    @Override
    public boolean unWall(AcademicCommonVo academicCommonVo) {
        List<Long> ids = academicCommonVo.getIds();
        if (ids != null && !ids.isEmpty()) {
            List<PacAcademicOutput> list = new ArrayList<>();
            ids.forEach(item -> {
                PacAcademicOutput pacAcademicOutput = new PacAcademicOutput();
                pacAcademicOutput.setId(item);
                pacAcademicOutput.setAcWall(1);
                list.add(pacAcademicOutput);
            });
            if (updateBatchById(list)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 根据等级查询，数量
     *
     * @param id
     * @return
     */
    @Override
    public int countByLevel(Integer id) {
        return Math.toIntExact(lambdaQuery().eq(PacAcademicOutput::getResultTypeId, id).count());
    }

    /**
     * 获取前三
     *
     * @param builder
     * @return
     */
    @Override
    public List<HonorWallTopThreeVo> getTopThree(WallTopThree builder) {
        List<PacAcademicOutput> list = lambdaQuery()
                .eq(PacAcademicOutput::getAcWall, WallStateEnum.WALL_STATE_YES.getCode())
                .eq(Objects.nonNull(builder.getFileType()), PacAcademicOutput::getAcFileType, builder.getFileType())
                .eq(Objects.nonNull(builder.getStuId()), PacAcademicOutput::getStuId, builder.getStuId())
                .between(Objects.nonNull(builder.getStartTime()), PacAcademicOutput::getCreateTime, builder.getStartTime(), builder.getEndTime())
                .orderByDesc(PacAcademicOutput::getCreateTime)
                .last("LIMIT 3")
                .list();

        if (list != null && !list.isEmpty()) {
            return list.stream().map(item -> {
                HonorWallTopThreeVo honorWallTopThreeVo = new HonorWallTopThreeVo();
                honorWallTopThreeVo.setAcTitle(item.getAcTitle());
                honorWallTopThreeVo.setAcFile(item.getAcFile());
                honorWallTopThreeVo.setAcFileType(item.getAcFileType());
                honorWallTopThreeVo.setStuName(item.getStuName());
                return honorWallTopThreeVo;
            }).collect(Collectors.toList());
        }

        return new ArrayList<>();
    }

    /**
     * 获取学生的荣誉列表
     *
     * @param wallTopThree
     * @return
     */
    @Override
    public List<HonorWallTopThreeVo> getStuHonorList(WallTopThree wallTopThree) {
        List<PacAcademicOutput> list = lambdaQuery()
                .eq(Objects.nonNull(wallTopThree.getFileType()), PacAcademicOutput::getAcFileType, wallTopThree.getFileType())
                .eq(Objects.nonNull(wallTopThree.getStuId()), PacAcademicOutput::getStuId, wallTopThree.getStuId())
                .orderByDesc(PacAcademicOutput::getCreateTime)
                .list();

        if (list != null && !list.isEmpty()) {
            return list.stream().map(item -> {
                HonorWallTopThreeVo honorWallTopThreeVo = new HonorWallTopThreeVo();
                honorWallTopThreeVo.setAcTitle(item.getAcTitle());
                honorWallTopThreeVo.setAcFile(item.getAcFile());
                honorWallTopThreeVo.setAcFileType(item.getAcFileType());
                honorWallTopThreeVo.setStuName(item.getStuName());
                return honorWallTopThreeVo;
            }).collect(Collectors.toList());
        }

        return new ArrayList<>();
    }

    /**
     * 获取高质量奖项 数量
     *
     * @return
     */
    @Override
    public long getHighQualityCount() {
        long count = pacAcademicOutputMapper.getHighQualityCount();
        return count;
    }

    /**
     * 通过审核的数量
     *
     * @return
     */
    @Override
    public long countByAudit() {
        long count = lambdaQuery().eq(PacAcademicOutput::getAcAudit, 2).count();
        return count;
    }

    /**
     * 找到是图片数据的前五
     *
     * @param id
     * @return
     */
    @Override
    public List<PacAcademicOutput> selectStuTop5(Integer id) {
        List<PacAcademicOutput> list = lambdaQuery()
                .eq(PacAcademicOutput::getAcFileType, FileTypeEnum.IMAGE.getCode())
                .eq(PacAcademicOutput::getStuId, id)
                .eq(PacAcademicOutput::getAcAudit, AuditStatusEnum.AUDITED.getCode())
                .orderByDesc(PacAcademicOutput::getCreateTime)
                .last("LIMIT 5")
                .list();
        return list;
    }

    @Override
    public List<PacAcademicOutput> getListByIds(List<Long> ids) {
        List<PacAcademicOutput> list = lambdaQuery()
                .in(PacAcademicOutput::getId, ids)
                .list();
        return list;
    }


    private static PacAuditRecords getPacAuditRecords(PacAcademicOutput pacAcademicOutput, Student student) {
        PacAuditRecords pacAuditRecords = new PacAuditRecords();
        pacAuditRecords.setAuditType(AuditTypeEnum.PAC_WALL_TYPE_ACADEMIC.getCode());
        pacAuditRecords.setAuditStu(pacAcademicOutput.getStuName());
        pacAuditRecords.setAuditStuClass(student.getStuClass());
        pacAuditRecords.setAuditFile(pacAcademicOutput.getAcFile());
        pacAuditRecords.setAuditTitle(pacAcademicOutput.getAcTitle());
        pacAuditRecords.setAuditStuId(pacAcademicOutput.getStuId());
        pacAuditRecords.setAuditRecordId(pacAcademicOutput.getId());
        pacAuditRecords.setAuditFileType(pacAcademicOutput.getAcFileType());
        return pacAuditRecords;
    }

}




